I am trying to use a variable for the name of an attribute but keep getting an error. I have the following:
for (obj in current Module) do {
for (sAttr in skUnusedAttr) do {
if (obj(sAttr) != "") {
//Do something
}
}
}
but I get an error saying "incorrect arguments for (!=)". What's the correct way to do this, then?
Chris Christopher Cote - Fri Apr 26 12:56:51 EDT 2019 |
Re: Using a variable for an object's attribute
AttrDef ad
Module m = current
Skip sk = create
for ad in m do {
if (ad.object and !ad.system) {
put (sk, ad, ad)
}
}
Object o
for o in entire m do {
for ad in sk do {
string sAttr = ad.name
print "checking " sAttr " for object " o."Absolute Number" "\n"
if (o.sAttr "" == "") {
print sAttr " is not used in object " o."Absolute Number" "\n"
}
}
break // for demonstration purposes, stop after the first object, otherwise printing would take too much time
}
|
Re: Using a variable for an object's attribute to be a bit more complete:
AttrDef ad
Module m = current
Skip sk = create
for ad in m do {
if (ad.object and !ad.system) {
put (sk, ad, ad)
}
}
Object o
for o in entire m do {
Skip oldskip = sk
Skip newskip = create
for ad in sk do {
string sAttr = ad.name
// print "checking " sAttr " for object " o."Absolute Number" "\n"
if (o.sAttr "" != "") {
print sAttr " is used in object " o."Absolute Number" " and possibly in other objects\n"
// directly removing ad from sk here is a no-no, never delete something that you iterate over
} else {
// instead, put all the AttrDefs that are still candidates for unused ADs into a new skip
put (newskip, ad, ad)
}
}
delete oldskip
sk = newskip
// break
}
// which AttrDefs are not used?
print "not used are the following AttrDefs:\n"
for ad in sk do {
print ad.name ", "
}
print "\n"
Output: Priority is used in object 1418 Review is used in object 1418 ObjectType is used in object 1418 DeXI_Modifications is used in object 1418 BRS_Variante is used in object 1992 ReviewComment is used in object 1852 Comment (AE-BE/EKE) is used in object 1481 Status (AE-BE/EKE) is used in object 1481 DeXI_ModifiedAttribs is used in object 1481 not used are the following AttrDefs: Accurateness, BitSize, ComputationCycle, CustomerRelease, ComponentCategory, CustomerVariant, DefaultValue, Comment, ComponentType, LinkToTest, PWM_FrequenceMin, RBID, ReactionTime, Resolution1, Resolution2, PWM_FrequenceMax, LowerLimit2, OutLink, LowerLimit1, ModuleVersion, Unit2, UpperLimit1, SW_SignalName, SW_Variable2, SafetyGoal, SystemRelease, SW_DataType1, SubSystem, Test ID, Unit1, SW_Datatype2, SW_Variable1, SignalType, SystemFunction, DeXI_viewChapNum, Direction, EditState, DutyCycleMax, Interfaces, Latency, Integrationsstufen, DutyCycleMin, HW_Module, HW_ModuleVariant, HW_SignalName, InLink, Interpretation, FunctionRelease, UpperLimit2, VerificationCriteria, Application, ASIL,
|
Re: Using a variable for an object's attribute Mike.Scharnow - Fri Apr 26 16:51:44 EDT 2019 to be a bit more complete:
AttrDef ad
Module m = current
Skip sk = create
for ad in m do {
if (ad.object and !ad.system) {
put (sk, ad, ad)
}
}
Object o
for o in entire m do {
Skip oldskip = sk
Skip newskip = create
for ad in sk do {
string sAttr = ad.name
// print "checking " sAttr " for object " o."Absolute Number" "\n"
if (o.sAttr "" != "") {
print sAttr " is used in object " o."Absolute Number" " and possibly in other objects\n"
// directly removing ad from sk here is a no-no, never delete something that you iterate over
} else {
// instead, put all the AttrDefs that are still candidates for unused ADs into a new skip
put (newskip, ad, ad)
}
}
delete oldskip
sk = newskip
// break
}
// which AttrDefs are not used?
print "not used are the following AttrDefs:\n"
for ad in sk do {
print ad.name ", "
}
print "\n"
Output: Priority is used in object 1418 Review is used in object 1418 ObjectType is used in object 1418 DeXI_Modifications is used in object 1418 BRS_Variante is used in object 1992 ReviewComment is used in object 1852 Comment (AE-BE/EKE) is used in object 1481 Status (AE-BE/EKE) is used in object 1481 DeXI_ModifiedAttribs is used in object 1481 not used are the following AttrDefs: Accurateness, BitSize, ComputationCycle, CustomerRelease, ComponentCategory, CustomerVariant, DefaultValue, Comment, ComponentType, LinkToTest, PWM_FrequenceMin, RBID, ReactionTime, Resolution1, Resolution2, PWM_FrequenceMax, LowerLimit2, OutLink, LowerLimit1, ModuleVersion, Unit2, UpperLimit1, SW_SignalName, SW_Variable2, SafetyGoal, SystemRelease, SW_DataType1, SubSystem, Test ID, Unit1, SW_Datatype2, SW_Variable1, SignalType, SystemFunction, DeXI_viewChapNum, Direction, EditState, DutyCycleMax, Interfaces, Latency, Integrationsstufen, DutyCycleMin, HW_Module, HW_ModuleVariant, HW_SignalName, InLink, Interpretation, FunctionRelease, UpperLimit2, VerificationCriteria, Application, ASIL,
Now I'm getting an error that says: "incorrect use of identifier (create)" on a line that says "Skip sk = create". Here is the function:
void getUnusedAttrs() {
bool objChecked = false;
AttrDef ad;
Module m = current;
Skip sk = create;
for ad in m do {
if (ad.object and !ad.system) {
put(sk, ad, ad);
}
}
string sAttr = "";
Object obj;
for obj in entire m do {
for ad in sk do {
sAttr = ad.name;
if (obj.sAttr "" == "") {
print sAttr " is not used in object " obj."Absolute Number" "\n";
}
}
}
}
This doesn't make any sense!! If I change create to createString, the function runs without the error. Chris |
Re: Using a variable for an object's attribute Christopher Cote - Mon Apr 29 10:06:44 EDT 2019 Now I'm getting an error that says: "incorrect use of identifier (create)" on a line that says "Skip sk = create". Here is the function:
void getUnusedAttrs() {
bool objChecked = false;
AttrDef ad;
Module m = current;
Skip sk = create;
for ad in m do {
if (ad.object and !ad.system) {
put(sk, ad, ad);
}
}
string sAttr = "";
Object obj;
for obj in entire m do {
for ad in sk do {
sAttr = ad.name;
if (obj.sAttr "" == "") {
print sAttr " is not used in object " obj."Absolute Number" "\n";
}
}
}
}
This doesn't make any sense!! If I change create to createString, the function runs without the error. Chris cannot confirm this. I pasted your code without any modification to a DXL window, say "run" and I get no output / no error message add a line getUnusedAttrs() and I get the expected output
Perhaps you should delete your code and paste it again from this post and check whether there are similar errors |
Re: Using a variable for an object's attribute Mike.Scharnow - Mon Apr 29 11:43:12 EDT 2019 cannot confirm this. I pasted your code without any modification to a DXL window, say "run" and I get no output / no error message add a line getUnusedAttrs() and I get the expected output
Perhaps you should delete your code and paste it again from this post and check whether there are similar errors I figured that issue out... I just had to add the parentheses and it worked fine. However, I'm now getting a very large skiplist when I put unused attributes into the skip. Here is my code:
Object o;
Module m = current;
Skip sk = create();
int numAttrs = 0;
for ad in m do {
if (ad.object and !ad.system) {
put (sk, ad, ad);
}
}
for o in entire m do {
Skip oldskip = sk;
Skip newskip = create();
for ad in sk do {
string sAttr = ad.name;
if (o.sAttr "" == "") {
if (!find(oldskip, ad, ad)) {
sizeOfSkip++;
put(newskip, ad, ad);
}
}
}
delete oldskip
sk = newskip
}
infoBox("Skip size: " sizeOfSkip "");
I'm pretty sure that the problem has to do with my 'find' function call. What should I be searching to make sure that a particular attribute definition doesn't exist yet in the skiplist so I don't increment sizeOfSkip?
Chris |
Re: Using a variable for an object's attribute Christopher Cote - Tue Apr 30 08:27:21 EDT 2019 I figured that issue out... I just had to add the parentheses and it worked fine. However, I'm now getting a very large skiplist when I put unused attributes into the skip. Here is my code:
Object o;
Module m = current;
Skip sk = create();
int numAttrs = 0;
for ad in m do {
if (ad.object and !ad.system) {
put (sk, ad, ad);
}
}
for o in entire m do {
Skip oldskip = sk;
Skip newskip = create();
for ad in sk do {
string sAttr = ad.name;
if (o.sAttr "" == "") {
if (!find(oldskip, ad, ad)) {
sizeOfSkip++;
put(newskip, ad, ad);
}
}
}
delete oldskip
sk = newskip
}
infoBox("Skip size: " sizeOfSkip "");
I'm pretty sure that the problem has to do with my 'find' function call. What should I be searching to make sure that a particular attribute definition doesn't exist yet in the skiplist so I don't increment sizeOfSkip?
Chris skip list have unique identifiers, so, if you add a key/value pair to a skip list where the key already exists, nothing will happen. I think that's simply a matter of variable initialization, Add a int sizeOfSkip=0 after line 13
And I would count the size at the very end of your program
int sizeOkSkip=0
for ad in sk do sizeOfSkip++
infoBox ("Skip size: " sizeOfSkip "")
|
Re: Using a variable for an object's attribute Mike.Scharnow - Tue Apr 30 08:43:48 EDT 2019 skip list have unique identifiers, so, if you add a key/value pair to a skip list where the key already exists, nothing will happen. I think that's simply a matter of variable initialization, Add a int sizeOfSkip=0 after line 13
And I would count the size at the very end of your program
int sizeOkSkip=0
for ad in sk do sizeOfSkip++
infoBox ("Skip size: " sizeOfSkip "")
You can force replacing a KEY in the Skip: put(skp, Key, Data, true) These two are the same: put(skp, Key, Data,) put(skp, Key, Data, false) -Louie |